package app.ui;

import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;

import javax.swing.JPanel;

public abstract class AbsCommonPanel extends JPanel {
	/**
		 * 
		 */
	private static final long serialVersionUID = -3750494764592451900L;

	protected MainFrame mFrame;

	public AbsCommonPanel(MainFrame mFrame) {
		super(null);
		this.mFrame = mFrame;
	}

	protected abstract void doAddComponents();

	public abstract void initializeComponents();

	public abstract void resizeComponents();

	/**
	 * Always using this method to add the panel to main frame This will
	 * automatically revoke the method resizeComponents()
	 */
	public void addThisToMainFrame() {
		/*-------------------------------------------------------------
		/* This is placed here to secure all component is initialize */
		this.addComponentListener(new PanelResize(this));
		/*-----------------------------------------------------------*/
		mFrame.add(this);
	}

	public MainFrame getmFrame() {
		return mFrame;
	}

	public void close(boolean remove) {
		this.displayThis(false);
		if (remove) {
			mFrame.remove(this);
		}
	}

	public void displayThis(boolean aFlag) {
		setVisible(aFlag);
		mFrame.getStartUi().setVisible(!aFlag);
	}
}

class PanelResize extends ComponentAdapter {
	AbsCommonPanel mPanel;

	public PanelResize(AbsCommonPanel mPanel) {
		super();
		this.mPanel = mPanel;
	}

	@Override
	public void componentResized(ComponentEvent e) {
		mPanel.resizeComponents();
	}
}
